import { DisposeView } from "../../../../mvc/core/DisposeView";
import { QiXingShenHunConfig } from "../../../resource/QiXingShenHunConfig";
import { PulseSharedObject } from "../../player/PulseSharedObject";
import { GameConst } from "../../../../component/gconst/GameConst";
import { Cache } from "../../../cache/Cache";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { CheckBoxWin } from "../../common/alertwins/CheckBoxWin";
import { Language } from "../../../../../extend/language/Language";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { EffectManager } from "../../../manager/EffectManager";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
type int = number;
//class GodSoulStarBtn
    
    export  class GodSoulStarBtn extends DisposeView
    {
        constructor()
        {
            super();
            return;
        }

        public set index(arg1: int)
        {
            this._index = arg1;
            this._name.text = QiXingShenHunConfig.instance.getName(arg1);
            return;
        }

        public get index(): int
        {
            return this._index;
        }

        public set state(arg1: int)
        {
            var $value: int;
            var isNeedAlert: Boolean;
            var clickHandler: Function;

            var loc1;
            clickHandler = null;
            $value = arg1;
            clickHandler = (arg1: int, arg2: Boolean): void
            {
                select();
                if (arg2) 
                {
                    PulseSharedObject.save("GodSoulTip", true);
                }
                return;
            }
            this._state = $value;
            isNeedAlert = !PulseSharedObject.isTodayNotTips("GodSoulTip" + this._index);
            if (isNeedAlert && this._state == 0 && !(this._index == 1) && this.canActivate && this._index <= GameConst.QixingShenhunMaxStar && Cache.instance.godSoul.needShowOpenTip) 
            {
                Cache.instance.godSoul.needShowOpenTip = false;
                Alert.alertWinRenderer = CheckBoxWin;
                Alert.show(Language.getStringByParam(28691, HTMLUtil.addColor(QiXingShenHunConfig.instance.getName(this._index), GlobalStyle.color6)), null, Alert.OK, null, clickHandler);
            }
            if (this._index == 7) 
            {
                Cache.instance.godSoul.needShowOpenTip = false;
            }
            return;
        }

        public get state(): int
        {
            return this._state;
        }

        public set level(arg1: int)
        {
            this._level = arg1;
            if (this.state == 1 && !(this._effectPlayer.url == this.getEffectNameByLv(arg1))) 
            {
                this._effectPlayer.move(40 / 2, 39 / 2);
                this._effectPlayer.load(this.getEffectNameByLv(arg1), ModelType.Item, null);
                this.addChild(this._effectPlayer);
            }
            else if (this.state == 0) 
            {
                this._effectPlayer.dispose();
            }
            return;
        }

        public get level(): int
        {
            return this._level;
        }

        public set exp(arg1: int)
        {
            this._exp = arg1;
            return;
        }

        public get exp(): int
        {
            return this._exp;
        }

        public get effectPlayer(): SWFPlayer
        {
            return this._effectPlayer;
        }

        public get canActivate(): Boolean
        {
            var loc1=Cache.instance.role.entityInfo.level;
            var loc2=Cache.instance.godSoul.levelInfo[(this.index - 1)];
            var loc3=this.index;
            switch (loc3) 
            {
                case 1:
                {
                    return loc1 >= 75;
                }
                case 2:
                {
                    return loc1 >= 80 || loc2 >= 80;
                }
                case 3:
                {
                    return loc1 >= 85 || loc2 >= 80;
                }
                case 4:
                {
                    return loc1 >= 90 || loc2 >= 80;
                }
                case 5:
                {
                    return loc1 >= 95 || loc2 >= 80;
                }
                case 6:
                {
                    return loc1 >= 100 || loc2 >= 80;
                }
                case 7:
                {
                    return loc1 >= 105 || loc2 >= 80;
                }
            }
            return false;
        }

        public select(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GodSoulStarSelect, this));
            return;
        }

        /* internal  */onClickStarHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.canActivate && this._index <= GameConst.QixingShenhunMaxStar) 
            {
                this.select();
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(28693));
            }
            return;
        }

        /* internal  */onStarSelectHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as GodSoulStarBtn;
            if (loc1 && loc1.effectPlayer && loc1.effectPlayer.isloadComplete) 
            {
                loc1.effectPlayer.updateCurrentFrame(0);
                loc1.effectPlayer.play();
            }
            return;
        }

        /* internal  */getEffectNameByLv(arg1: int): string
        {
            if (arg1 >= 0 && arg1 <= 19) 
            {
                return "GodSoulEffect_1.swf";
            }
            if (arg1 >= 20 && arg1 <= 39) 
            {
                return "GodSoulEffect_2.swf";
            }
            if (arg1 >= 40 && arg1 <= 59) 
            {
                return "GodSoulEffect_3.swf";
            }
            if (arg1 >= 60 && arg1 <= 79) 
            {
                return "GodSoulEffect_4.swf";
            }
            return "GodSoulEffect_5.swf";
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            this._btn = ObjCreate.createGLoadedButton(ResFileConst.GodSoulStarBtn, 0, 0, 40, 39, this);
            this._btn.configEventListener(flash.events.MouseEvent.CLICK, this.onClickStarHandler);
            this._name = ObjCreate.createGTextField("", 6, 45, 40, 20, this, GlobalStyle._textFormat6);
            if (!this._effectPlayer) 
            {
                this._effectPlayer = new SWFPlayer();
                this._effectPlayer.move(40 / 2, 39 / 2);
            }
            Dispatcher.addEventListener(EventName.GodSoulStarSelect, this.onStarSelectHandler);
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            super.disposeImpl(arg1);
            this._btn.dispose(arg1);
            this._name.dispose(arg1);
            this._effectPlayer.dispose(arg1);
            EffectManager.glowFilterUnReg(this._btn);
            this._btn = null;
            this._name = null;
            return;
        }

        /* internal */ /* var */_index: int;

        /* internal */ /* var */_state: int;

        /* internal */ /* var */_level: int;

        /* internal */ /* var */_exp: int;

        /* internal */ /* var */_name: GTextFiled;

        /* internal */ /* var */_btn: GLoadedButton;

        /* internal */ /* var */_effectPlayer: SWFPlayer;
    }
